﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LikeUs.MovieServices;

namespace LikeUsWebSite
{
    public partial class Movies : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            get_Movies();
        }

        protected void get_Movies()
        {
            if (!Page.IsPostBack)
            {
                //***************** Us Example **************************
                //MovieApiService likeusApi = new MovieApiService();
                //LikeUsMovie luMovie = likeusApi.GetMovieById(771249559);
                //List<LikeUsMovie> list1 = likeusApi.GetBoxOfficeList();
                //List<int> movieId = new List<int>();
                //movieId.Add(771249559);
                //movieId.Add(771313372);
                //List<LikeUsMovie> list2 = likeusApi.GetMovieCollection(movieId);
                //List<LikeUsMovie> list3 = likeusApi.GetMoviesInTheaterList();
                //List<LikeUsMovie> list4 = likeusApi.GetOpeningMoviesList();
                //List<LikeUsMovie> list5 = likeusApi.GetUpcomingMoviesList();
                //List<LikeUsMovie> list6 = likeusApi.SearchMovie("Argo");

                //No need for Try Catch

                //***********************************************************
                string result = "";
                List<LikeUsMovie> movieRes;
                BulletedList1.Items.Clear();
                result += "Search Results: ";
                MovieApiService likeusApi = new MovieApiService();

                movieRes = likeusApi.GetBoxOfficeList();
                //ListView1.DataSource = movieRes;
                Panel2.Controls.Add(new LiteralControl());
                LiteralControl objPanelText = Panel2.Controls[0] as LiteralControl;
                if (movieRes.Count != 0)
                {
                    result += movieRes.Count.ToString();
                    //   if (movieRes[0].Posters.Count != 0)
                    //  {
                    //  Image1.ImageUrl = movieRes[0].Posters[0].ImageInfo.Url;
                    // Image1.Visible = true;
                    //Image img = new Image();
                    //img.ImageUrl = movieRes[0].Posters[0].ImageInfo.Url;
                    //img.Page = this.Page;
                    //img.Visible = true;
                    //this.Items.Add(1234, img);

                    // }
                    
                   result +="<table cellspacing=2>";
                    foreach (LikeUsMovie movie in movieRes)
                    {
                        try
                        { 
                            result +="<tr><td><img src='" + movie.PosterSmall + "'/></td><td><b>" + movie.Title + "</b></td><td>" + movie.Synopsis + "</td></tr>";
                        }
                        catch (Exception e)
                        {
                            result += "<tr><td>/td><td><b>" + movie.Title + "</b></td><td>" + movie.Synopsis + "</td></tr>";
                        }
                    }
                   result +="</table>";
                }
                else
                {
                    result += "0";
                }

                objPanelText.Text = result;
            }
        }

    }
}
